<template>
  <div class="sortplanupdate-box">
    <div class="sortTitle">编辑分拣单基本资料</div>
    <div class="sortingOrder_list">
      <div class="block">
        <span class="demonstration">分拣线</span>
        <el-input v-model="SortingLine" class="inp" placeholder="请选择" disabled></el-input>
      </div>
      <div class="block">
        <span class="demonstration">班次</span>
        <el-input class="inp" placeholder="早班" disabled v-if="this.Sortinginfo.shifts==1"></el-input>
        <el-input class="inp" placeholder="晚班" disabled v-if="this.Sortinginfo.shifts==2"></el-input>
      </div>
      <div class="block">
        <span class="demonstration">时间</span>
        <el-date-picker
          v-model="valTime"
          type="datetimerange"
          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
          value-format="yyyy-MM-dd HH:mm:ss"
        ></el-date-picker>
      </div>
      <div class="block">
        <span class="demonstration">分拣状态</span>
        <el-select v-model="Sortinginfo.status" placeholder="请选择" @change="handleChange">
          <el-option
            v-for="item in state"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          ></el-option>
        </el-select>
      </div>
      <div class="block">
        <span class="demonstration">上班人数</span>
        <el-input v-model="Sortinginfo.worker" class="inp" placeholder="请选择"></el-input>
      </div>
    </div>
    <div class="btn-box">
      <el-button size="mini" type="primary" class="succeedbtn" @click="getsortplanupdate">确认</el-button>
    </div>
  </div>
</template>

<script>
//这里可以导入其他文件（比如：组件，工具js，第三方插件js，json文件，图片文件等等）
//例如：import 《组件名称》 from '《组件路径》';
import { getsortplanupdate, supervisor } from "@/api/user";
export default {
  //import引入的组件需要注入到对象中才能使用
  components: {},
  data() {
    //这里存放数据
    return {
      options: [],
      stat: [],
      state: [
        { value: "0", label: "排产" },
        { value: "1", label: "加工" },
        { value: "2", label: "完成" }
      ],
      value1: [],
      valTime: [],
      Sortinginfo: {},
      sortingStatus: "",
      SortingLine: "",
      val: [],
      values: [],
      worknum: 0,
      worknum: ""
    };
  },
  //监听属性 类似于data概念
  computed: {},
  //监控data中的数据变化
  watch: {},
  mounted() {
    this.Sorting();
  },
  //方法集合
  methods: {
    Sorting() {
      let valTime = this.valTime;
      this.Sortinginfo = this.$route.query;
      this.SortingLine = `${this.Sortinginfo.sortLineName} ${"/"} ${
        this.Sortinginfo.supervisorName
      }`;
      valTime.push(
        this.Sortinginfo.startAllocatingDate,
        this.Sortinginfo.endAllocatingDate
      );
      if (this.Sortinginfo.status == 0) {
        this.Sortinginfo.status = "排产";
      } else if (this.Sortinginfo.status == 1) {
        this.Sortinginfo.status = "加工";
      } else {
        this.Sortinginfo.status = "完成";
      }
    },
    getsortplanupdate() {
      let id = this.$route.query.id;
      let data = {
        supervisorId: this.Sortinginfo.supervisorId,
        sortLineId: this.Sortinginfo.sortLineId,
        workType: this.Sortinginfo.shifts,
        workCount: this.Sortinginfo.worker,
        startTime: this.valTime[0],
        endTime: this.valTime[1],
        id: this.$route.query.id
      };
      getsortplanupdate(data).then(res => {
        console.log(res);
        if (res.code == 20000) {
          this.$message(res.msg);
          this.$router.push({
            name: "menu2",
            query: { id: this.$route.query.id }
          });
        }
      });
    },
    toorderdeteil() {
      let id = this.$route.query.id;
      this.$router.push({
        name: "order",
        params: { id: id }
      });
    },
    handleChange(value) {
      console.log(value);
    }
  },
  //生命周期 - 创建完成（可以访问当前this实例）
  created() {
    console.log(this.$route.query);
  },
  //生命周期 - 挂载完成（可以访问DOM元素）
  beforeCreate() {}, //生命周期 - 创建之前
  beforeMount() {}, //生命周期 - 挂载之前
  beforeUpdate() {}, //生命周期 - 更新之前
  updated() {}, //生命周期 - 更新之后
  beforeDestroy() {}, //生命周期 - 销毁之前
  destroyed() {}, //生命周期 - 销毁完成
  activated() {} //如果页面有keep-alive缓存功能，这个函数会触发
};
</script>
<style lang='scss' scoped>
//@import url(); 引入公共css类
.sortplanupdate-box {
  width: 100%;
  .sortTitle {
    margin: 20px;
  }
  .sortingOrder_list {
    width: 100%;
    .block {
      margin-bottom: 15px;
    }

    .demonstration {
      padding: 0 20px;
    }
    .searchInput {
      width: 200px;
      // height: 100px;
    }
    .block {
      display: inline-block;
      .dainji {
        display: inline-block;
        margin-right: 10px;
      }
      .inp {
        width: 200px;
      }
    }
    .xuanzeqi {
      display: inline-block;
    }
    .title {
      padding: 0 20px;
    }
  }
  .btn-box {
    width: 100%;
    display: flex;
    justify-content: flex-end;
    padding-right: 100px;
    box-sizing: border-box;
    .cleanbtn {
      width: 100px;
      height: 40px;
    }
    .succeedbtn {
      width: 100px;
      height: 40px;
    }
  }
}
</style>